<html><head><title>Packer.pb</title></head>
<body bgcolor="#FFFFDF" link="#009999" vlink="#006666" alink="#006666">
<pre><font face="Courier New, Courier, mono"size="2"><font color="#006666">;
</font><font color="#006666">; ------------------------------------------------------------
</font><font color="#006666">;
</font><font color="#006666">;   PureBasic - Compressor example file
</font><font color="#006666">;
</font><font color="#006666">;    (c) Fantaisie Software
</font><font color="#006666">;
</font><font color="#006666">; ------------------------------------------------------------
</font><font color="#006666">;
</font>
<font color="#006666">UseBriefLZPacker</font>() <font color="#006666">; Small and fast packer
</font>
<b><font color="#006666">If</font></b> <font color="#006666">ReadFile</font>(0,<font color="#006666"> OpenFileRequester</font>("Choose a file to compress", "", "*.*", 0))
  FileLength =<font color="#006666"> Lof</font>(0)
  
  <font color="#006666">; Allocate the 2 memory buffers needed for compression..
</font>  <font color="#006666">;
</font>  *Source =<font color="#006666"> AllocateMemory</font>(FileLength)
  *Target =<font color="#006666"> AllocateMemory</font>(FileLength)
  <b><font color="#006666">If</font></b> FileLength <b><font color="#006666">And</font></b> *Source <b><font color="#006666">And</font></b> *Target
<font color="#006666">    ReadData</font>(0, *Source, FileLength) <font color="#006666">; Read the whole file in the memory buffer
</font>    
    <font color="#006666">; Compress the file, which is in memory (and use a timer to see the time spend by compression..)
</font>    <font color="#006666">;
</font>    CompressedLength =<font color="#006666"> CompressMemory</font>(*Source, FileLength, *Target, FileLength)
    <b><font color="#006666">If</font></b> CompressedLength

      DecompressedLength =<font color="#006666"> UncompressMemory</font>(*Target, CompressedLength, *Source, FileLength)
      <b><font color="#006666">If</font></b> DecompressedLength = FileLength
<font color="#006666">        MessageRequester</font>("Info", "De/Compression succeded:"+<font color="#924B72">#LF$</font>+<font color="#924B72">#LF$</font>+"Old size: "+<font color="#006666">Str</font>(FileLength)+<font color="#924B72">#LF$</font>+"New size: "+<font color="#006666">Str</font>(CompressedLength))
      <b><font color="#006666">EndIf</font></b>
    <b><font color="#006666">Else</font></b>
<font color="#006666">      MessageRequester</font>("Error", "Can't compress the file")
    <b><font color="#006666">EndIf</font></b> 
    
<font color="#006666">    FreeMemory</font>(*Source)
<font color="#006666">    FreeMemory</font>(*Target)
    
  <b><font color="#006666">EndIf</font></b>
  
<font color="#006666">  CloseFile</font>(0)
<b><font color="#006666">EndIf</font></b>

<b><font color="#006666">End</font></b>
</font></pre>
</body></html>
